package com.dq.domain.sys.user.user.centre;

import com.alibaba.fastjson.JSONObject;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.WxUser;
import com.dq.utils.TimeUtil;
import com.dq.vo.baseVo.VO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author cf
 */
@Data
@Entity
@ApiModel("会员卡实体")
public class UserCard extends BaseEntity implements VO.ToVO {
    @ApiModelProperty(value = "会员卡号", hidden = true)
    protected String cardNo ;
    @ApiModelProperty(value = "所属人")
    @ManyToOne
    protected WxUser wxUser ;
    @ApiModelProperty(value = "所属店铺")
    @ManyToOne
    protected Org org;
    @ApiModelProperty(value = "剩余充值总金额")
    @Column(columnDefinition="decimal default 0")
    protected BigDecimal price;
    @ApiModelProperty(value = "剩余赠送总金额")
    @Column(columnDefinition="decimal default 0")
    protected BigDecimal givePrice;

    @ApiModelProperty("类型, 积分卡/次数卡")
    @Enumerated(EnumType.ORDINAL)
    protected CardType cardType;

    @ApiModelProperty("状态，禁用/激活")
    @Enumerated(EnumType.ORDINAL)
    protected Status status;

    public enum CardType {
        one("积分卡"),
        two("次数卡"),;

        CardType(String name) {
            this.name = name;
        }
        public String name;
    }

    public enum Status{
        on("激活"),
        off("禁用")
        ;
        public String name;
        Status(String name){
            this.name = name;
        }
    }

    @Data
    @ApiModel(value = "视图")
    public static class Vo implements VO {
        protected Long id;
        @ApiModelProperty(value = "会员卡号")
        protected String cardNo ;
        @ApiModelProperty(value = "所属人")
        protected Long wxUserId;
        protected String wxUserRealcName;
        protected String mobile;
        @ApiModelProperty(value = "所属店铺")
        protected Long orgId;
        protected String orgSimpleName;

        @ApiModelProperty("类型, 积分卡/次数卡")
        protected String cardTypeCn;
        protected String cardTypeEn;
        protected String statusCn;
        protected String statusEn;

        @ApiModelProperty(value = "剩余充值总金额")
        protected BigDecimal price;
        @ApiModelProperty(value = "剩余赠送总金额")
        protected BigDecimal givePrice;

        @ApiModelProperty("次数卡 类型, 关联的服务项目信息")
        protected List<JSONObject> serviceProjectList;

        @ApiModelProperty(value = "开卡人")
        protected Long createUserId;
        protected String createUserRealcName;
        protected String createTime;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.cardNo = this.getCardNo();
        vo.wxUserId = this.getWxUser().getId();
        vo.wxUserRealcName = this.getWxUser().getUserRealcName();
        vo.mobile = fmt(this.getWxUser().getMobile());
        vo.orgId = this.getOrg().getId();
        vo.orgSimpleName = this.getOrg().getSimpleName();
        vo.price = fmt(this.getPrice());
        vo.givePrice = fmt(this.getGivePrice());
        vo.cardTypeCn = this.getCardType().name;
        vo.cardTypeEn = this.getCardType().toString();
        vo.statusCn = this.getStatus().name;
        vo.statusEn = this.getStatus().toString();


        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserRealcName = this.createUser == null ? null : this.createUser.getUserRealcName();
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }
}
